﻿namespace TriangleGames.TrainRes
{
    using System;
    using UnityEngine;

    [Serializable]
    public class FsmVariables
    {
        [SerializeField]
        private FsmBool[] boolVariables;
        [SerializeField]
        private FsmColor[] colorVariables;
        [SerializeField]
        private FsmFloat[] floatVariables;
        [SerializeField]
        private FsmGameObject[] gameObjectVariables;
        [SerializeField]
        private FsmInt[] intVariables;
        [SerializeField]
        private FsmMaterial[] materialVariables;
        [SerializeField]
        private FsmObject[] objectVariables;
        [SerializeField]
        private FsmQuaternion[] quaternionVariables;
        [SerializeField]
        private FsmRect[] rectVariables;
        [SerializeField]
        private FsmString[] stringVariables;
        [SerializeField]
        private FsmTexture[] textureVariables;
        [SerializeField]
        private FsmVector3[] vector3Variables;

        public FsmVariables()
        {
            this.floatVariables = new FsmFloat[0];
            this.intVariables = new FsmInt[0];
            this.boolVariables = new FsmBool[0];
            this.stringVariables = new FsmString[0];
            this.vector3Variables = new FsmVector3[0];
            this.colorVariables = new FsmColor[0];
            this.rectVariables = new FsmRect[0];
            this.quaternionVariables = new FsmQuaternion[0];
            this.gameObjectVariables = new FsmGameObject[0];
            this.objectVariables = new FsmObject[0];
            this.materialVariables = new FsmMaterial[0];
            this.textureVariables = new FsmTexture[0];
        }

        public FsmVariables(FsmVariables source)
        {
            this.floatVariables = new FsmFloat[0];
            this.intVariables = new FsmInt[0];
            this.boolVariables = new FsmBool[0];
            this.stringVariables = new FsmString[0];
            this.vector3Variables = new FsmVector3[0];
            this.colorVariables = new FsmColor[0];
            this.rectVariables = new FsmRect[0];
            this.quaternionVariables = new FsmQuaternion[0];
            this.gameObjectVariables = new FsmGameObject[0];
            this.objectVariables = new FsmObject[0];
            this.materialVariables = new FsmMaterial[0];
            this.textureVariables = new FsmTexture[0];
            if (source != null)
            {
                this.floatVariables = new FsmFloat[source.floatVariables.Length];
                for (int i = 0; i < source.floatVariables.Length; i++)
                {
                    this.floatVariables[i] = new FsmFloat(source.floatVariables[i]);
                }
                this.intVariables = new FsmInt[source.intVariables.Length];
                for (int j = 0; j < source.intVariables.Length; j++)
                {
                    this.intVariables[j] = new FsmInt(source.intVariables[j]);
                }
                this.boolVariables = new FsmBool[source.boolVariables.Length];
                for (int k = 0; k < source.boolVariables.Length; k++)
                {
                    this.boolVariables[k] = new FsmBool(source.boolVariables[k]);
                }
                this.gameObjectVariables = new FsmGameObject[source.gameObjectVariables.Length];
                for (int m = 0; m < source.gameObjectVariables.Length; m++)
                {
                    this.gameObjectVariables[m] = new FsmGameObject(source.gameObjectVariables[m]);
                }
                this.colorVariables = new FsmColor[source.colorVariables.Length];
                for (int n = 0; n < source.colorVariables.Length; n++)
                {
                    this.colorVariables[n] = new FsmColor(source.colorVariables[n]);
                }
                this.vector3Variables = new FsmVector3[source.vector3Variables.Length];
                for (int num6 = 0; num6 < source.vector3Variables.Length; num6++)
                {
                    this.vector3Variables[num6] = new FsmVector3(source.vector3Variables[num6]);
                }
                this.rectVariables = new FsmRect[source.rectVariables.Length];
                for (int num7 = 0; num7 < source.rectVariables.Length; num7++)
                {
                    this.rectVariables[num7] = new FsmRect(source.rectVariables[num7]);
                }
                this.quaternionVariables = new FsmQuaternion[source.quaternionVariables.Length];
                for (int num8 = 0; num8 < source.quaternionVariables.Length; num8++)
                {
                    this.quaternionVariables[num8] = new FsmQuaternion(source.quaternionVariables[num8]);
                }
                this.objectVariables = new FsmObject[source.objectVariables.Length];
                for (int num9 = 0; num9 < source.objectVariables.Length; num9++)
                {
                    this.objectVariables[num9] = new FsmObject(source.objectVariables[num9]);
                }
                this.materialVariables = new FsmMaterial[source.materialVariables.Length];
                for (int num10 = 0; num10 < source.materialVariables.Length; num10++)
                {
                    this.materialVariables[num10] = new FsmMaterial(source.materialVariables[num10]);
                }
                this.textureVariables = new FsmTexture[source.textureVariables.Length];
                for (int num11 = 0; num11 < source.textureVariables.Length; num11++)
                {
                    this.textureVariables[num11] = new FsmTexture(source.textureVariables[num11]);
                }
                this.stringVariables = new FsmString[source.stringVariables.Length];
                for (int num12 = 0; num12 < source.stringVariables.Length; num12++)
                {
                    this.stringVariables[num12] = new FsmString(source.stringVariables[num12]);
                }
            }
        }

        public void ApplyVariableValues(FsmVariables source)
        {
            for (int i = 0; i < source.floatVariables.Length; i++)
            {
                this.floatVariables[i].Value = source.floatVariables[i].Value;
            }
            for (int j = 0; j < source.intVariables.Length; j++)
            {
                this.intVariables[j].Value = source.intVariables[j].Value;
            }
            for (int k = 0; k < source.boolVariables.Length; k++)
            {
                this.boolVariables[k].Value = source.boolVariables[k].Value;
            }
            for (int m = 0; m < source.gameObjectVariables.Length; m++)
            {
                this.gameObjectVariables[m].Value = source.gameObjectVariables[m].Value;
            }
            for (int n = 0; n < source.colorVariables.Length; n++)
            {
                this.colorVariables[n].Value = source.colorVariables[n].Value;
            }
            for (int num6 = 0; num6 < source.vector3Variables.Length; num6++)
            {
                this.vector3Variables[num6].Value = source.vector3Variables[num6].Value;
            }
            for (int num7 = 0; num7 < source.rectVariables.Length; num7++)
            {
                this.rectVariables[num7].Value = source.rectVariables[num7].Value;
            }
            for (int num8 = 0; num8 < source.quaternionVariables.Length; num8++)
            {
                this.quaternionVariables[num8].Value = source.quaternionVariables[num8].Value;
            }
            for (int num9 = 0; num9 < source.objectVariables.Length; num9++)
            {
                this.objectVariables[num9].Value = source.objectVariables[num9].Value;
            }
            for (int num10 = 0; num10 < source.materialVariables.Length; num10++)
            {
                this.materialVariables[num10].Value = source.materialVariables[num10].Value;
            }
            for (int num11 = 0; num11 < source.textureVariables.Length; num11++)
            {
                this.textureVariables[num11].Value = source.textureVariables[num11].Value;
            }
            for (int num12 = 0; num12 < source.stringVariables.Length; num12++)
            {
                this.stringVariables[num12].Value = source.stringVariables[num12].Value;
            }
        }

        public FsmBool GetFsmBool(string name)
        {
            foreach (FsmBool @bool in this.boolVariables)
            {
                if (@bool.Name == name)
                {
                    return @bool;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmBool bool2 in GlobalVariables.boolVariables)
                {
                    if (bool2.Name == name)
                    {
                        return bool2;
                    }
                }
            }
            return new FsmBool(name);
        }

        public FsmColor GetFsmColor(string name)
        {
            foreach (FsmColor color in this.colorVariables)
            {
                if (color.Name == name)
                {
                    return color;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmColor color2 in GlobalVariables.colorVariables)
                {
                    if (color2.Name == name)
                    {
                        return color2;
                    }
                }
            }
            return new FsmColor(name);
        }

        public FsmFloat GetFsmFloat(string name)
        {
            foreach (FsmFloat num in this.floatVariables)
            {
                if (num.Name == name)
                {
                    return num;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmFloat num2 in GlobalVariables.floatVariables)
                {
                    if (num2.Name == name)
                    {
                        return num2;
                    }
                }
            }
            return new FsmFloat(name);
        }

        public FsmGameObject GetFsmGameObject(string name)
        {
            foreach (FsmGameObject obj2 in this.gameObjectVariables)
            {
                if (obj2.Name == name)
                {
                    return obj2;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmGameObject obj3 in GlobalVariables.gameObjectVariables)
                {
                    if (obj3.Name == name)
                    {
                        return obj3;
                    }
                }
            }
            return new FsmGameObject(name);
        }

        public FsmInt GetFsmInt(string name)
        {
            foreach (FsmInt num in this.intVariables)
            {
                if (num.Name == name)
                {
                    return num;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmInt num2 in GlobalVariables.intVariables)
                {
                    if (num2.Name == name)
                    {
                        return num2;
                    }
                }
            }
            return new FsmInt(name);
        }

        public FsmMaterial GetFsmMaterial(string name)
        {
            foreach (FsmMaterial material in this.materialVariables)
            {
                if (material.Name == name)
                {
                    return material;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmMaterial material2 in GlobalVariables.materialVariables)
                {
                    if (material2.Name == name)
                    {
                        return material2;
                    }
                }
            }
            return new FsmMaterial(name);
        }

        public FsmObject GetFsmObject(string name)
        {
            foreach (FsmObject obj2 in this.objectVariables)
            {
                if (obj2.Name == name)
                {
                    return obj2;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmObject obj3 in GlobalVariables.objectVariables)
                {
                    if (obj3.Name == name)
                    {
                        return obj3;
                    }
                }
            }
            return new FsmObject(name);
        }

        public FsmQuaternion GetFsmQuaternion(string name)
        {
            foreach (FsmQuaternion quaternion in this.quaternionVariables)
            {
                if (quaternion.Name == name)
                {
                    return quaternion;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmQuaternion quaternion2 in GlobalVariables.quaternionVariables)
                {
                    if (quaternion2.Name == name)
                    {
                        return quaternion2;
                    }
                }
            }
            return new FsmQuaternion(name);
        }

        public FsmRect GetFsmRect(string name)
        {
            foreach (FsmRect rect in this.rectVariables)
            {
                if (rect.Name == name)
                {
                    return rect;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmRect rect2 in GlobalVariables.rectVariables)
                {
                    if (rect2.Name == name)
                    {
                        return rect2;
                    }
                }
            }
            return new FsmRect(name);
        }

        public FsmString GetFsmString(string name)
        {
            foreach (FsmString str in this.stringVariables)
            {
                if (str.Name == name)
                {
                    return str;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmString str2 in GlobalVariables.stringVariables)
                {
                    if (str2.Name == name)
                    {
                        return str2;
                    }
                }
            }
            return new FsmString(name);
        }

        public FsmTexture GetFsmTexture(string name)
        {
            foreach (FsmTexture texture in this.textureVariables)
            {
                if (texture.Name == name)
                {
                    return texture;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmTexture texture2 in GlobalVariables.textureVariables)
                {
                    if (texture2.Name == name)
                    {
                        return texture2;
                    }
                }
            }
            return new FsmTexture(name);
        }

        public FsmVector3 GetFsmVector3(string name)
        {
            foreach (FsmVector3 vector in this.vector3Variables)
            {
                if (vector.Name == name)
                {
                    return vector;
                }
            }
            if (GlobalVariables != null)
            {
                foreach (FsmVector3 vector2 in GlobalVariables.vector3Variables)
                {
                    if (vector2.Name == name)
                    {
                        return vector2;
                    }
                }
            }
            return new FsmVector3(name);
        }

        public NamedVariable[] GetNames(System.Type ofType)
        {
            if (ofType == typeof(FsmFloat))
            {
                return this.floatVariables;
            }
            if (ofType == typeof(FsmInt))
            {
                return this.intVariables;
            }
            if (ofType == typeof(FsmBool))
            {
                return this.boolVariables;
            }
            if (ofType == typeof(FsmString))
            {
                return this.stringVariables;
            }
            if (ofType == typeof(FsmVector3))
            {
                return this.vector3Variables;
            }
            if (ofType == typeof(FsmRect))
            {
                return this.rectVariables;
            }
            if (ofType == typeof(FsmQuaternion))
            {
                return this.quaternionVariables;
            }
            if (ofType == typeof(FsmObject))
            {
                return this.objectVariables;
            }
            if (ofType == typeof(FsmMaterial))
            {
                return this.materialVariables;
            }
            if (ofType == typeof(FsmTexture))
            {
                return this.textureVariables;
            }
            if (ofType == typeof(FsmColor))
            {
                return this.colorVariables;
            }
            if (ofType == typeof(FsmGameObject))
            {
                return this.gameObjectVariables;
            }
            return new NamedVariable[0];
        }

        public FsmBool[] BoolVariables
        {
            get
            {
                return this.boolVariables;
            }
            set
            {
                this.boolVariables = value;
            }
        }

        public FsmColor[] ColorVariables
        {
            get
            {
                return this.colorVariables;
            }
            set
            {
                this.colorVariables = value;
            }
        }

        public FsmFloat[] FloatVariables
        {
            get
            {
                return this.floatVariables;
            }
            set
            {
                this.floatVariables = value;
            }
        }

        public FsmGameObject[] GameObjectVariables
        {
            get
            {
                return this.gameObjectVariables;
            }
            set
            {
                this.gameObjectVariables = value;
            }
        }

        public static TrainResGlobalsCore GlobalsComponent
        {
            get
            {
                return TrainResGlobalsCore.Instance;
            }
        }

        public static FsmVariables GlobalVariables
        {
            get
            {
                return TrainResGlobalsCore.Instance.Variables;
            }
        }

        public FsmInt[] IntVariables
        {
            get
            {
                return this.intVariables;
            }
            set
            {
                this.intVariables = value;
            }
        }

        public FsmMaterial[] MaterialVariables
        {
            get
            {
                return this.materialVariables;
            }
            set
            {
                this.materialVariables = value;
            }
        }

        public FsmObject[] ObjectVariables
        {
            get
            {
                return this.objectVariables;
            }
            set
            {
                this.objectVariables = value;
            }
        }

        public FsmQuaternion[] QuaternionVariables
        {
            get
            {
                return this.quaternionVariables;
            }
            set
            {
                this.quaternionVariables = value;
            }
        }

        public FsmRect[] RectVariables
        {
            get
            {
                return this.rectVariables;
            }
            set
            {
                this.rectVariables = value;
            }
        }

        public FsmString[] StringVariables
        {
            get
            {
                return this.stringVariables;
            }
            set
            {
                this.stringVariables = value;
            }
        }

        public FsmTexture[] TextureVariables
        {
            get
            {
                return this.textureVariables;
            }
            set
            {
                this.textureVariables = value;
            }
        }

        public FsmVector3[] Vector3Variables
        {
            get
            {
                return this.vector3Variables;
            }
            set
            {
                this.vector3Variables = value;
            }
        }
    }
}

